<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="box-card">
        <el-tabs v-model="activeName">

          <!-- 登陆账号表单 -->
          <el-tab-pane label="登录账户设置" name="first">
            <el-form ref="form" :model="basicForm" label-width="120px" style="margin: 30px 0 0 120px" :rules="rules">
              <el-form-item label="姓名: " prop="username">
                <el-input v-model="basicForm.username" style="width: 25%" />
              </el-form-item>
              <el-form-item label="密码: " prop="password">
                <el-input v-model="basicForm.password2" type="password" style="width: 25%" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmitFn">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>

          <!-- 个人详情表单 -->
          <el-tab-pane label="个人详情" name="second">
            <!-- <user-info /> -->
            <component :is="UserInfo" />
          </el-tab-pane>

          <!-- 岗位信息表单 -->
          <el-tab-pane label="岗位信息" name="third">
            <JobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getuserAPI, setuserAPI } from '@/api/employees'
import UserInfo from './components/user-info.vue'
import JobInfo from './components/job-info.vue'
export default {
  components: {
    UserInfo, JobInfo
  },
  // eslint-disable-next-line vue/require-prop-types
  props: ['id'],
  data() {
    return {
      activeName: 'first',
      basicForm: {}, // 员工基本信息表单
      UserInfo: 'UserInfo',
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 2, max: 6, message: '长度在 2 到 6 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 9, message: '长度在 6 到 9个字符', trigger: 'blur' }
        ]
      }
    }
  },
  mounted() {
    this.getusersFn()
  },
  methods: {
    async onSubmitFn() {
      this.basicForm.password = this.basicForm.password2
      await setuserAPI(this.basicForm)
      this.$message.success('更新成功')
      this.getusersFn()
    },
    async getusersFn() {
      this.basicForm = await getuserAPI(this.id)
    }
  }
}
</script>

<style scoped>
</style>
